Skip to content

fix(devices): detect the SD write-protect lock on Windows - #245

Open
SuperKali wants to merge 1 commit into
mainfrom
fix/windows-sd-lock-detection
Open

SuperKali wants to merge 1 commit into
mainfrom
fix/windows-sd-lock-detection

Conversation

@SuperKali

Copy link
Copy Markdown
Member

Description

On Windows the app never saw the lock switch on an SD card. The media query used a hand-written control code, 0x002D0030, that is not a real one (it came in with #97), so the call always failed and a failure counts as writable. A locked card was offered as a normal target and the write failed later.

I now take the code from windows-sys and read the reply byte by byte instead of casting it to structs. A locked card shows as "Locked" and is refused before writing, as on Linux and macOS. A reader error still counts as writable, so it cannot block a working card.

How Has This Been Tested?

  • npm run lint and npx tsc --noEmit -p tsconfig.app.json pass
  • cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings (also for the Windows target) and cargo test pass
  • Tried in the app on Windows with a locked card: not yet, I have no Windows machine with a card reader

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings

The media query used an ioctl code that does not exist, so it always
failed and a locked SD card counted as writable. The code now comes
from windows-sys and the replies are parsed byte by byte.
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🧪 Test Builds

Version: 0.0.0-pr.245 | PR: #245 | Commit: 84589f8 | Status: ready for testing

Platform Download
Linux x64 📦 .deb / .AppImage
Windows x64 📦 .exe
macOS ARM64 📦 .dmg
How to run these test builds

macOS (Apple Silicon):
The app is ad-hoc signed; you may see a quarantine warning. Go to System Settings > Privacy & Security, scroll to the Security section at the bottom, find Armbian Imager, and click "Open Anyway". Or use:

xattr -dr com.apple.quarantine /Applications/Armbian\ Imager.app

Windows:
Windows Defender SmartScreen may warn. Click "More info" then "Run anyway", and grant Administrator when prompted.

Linux:
Make AppImage executable and run, or install the .deb:

chmod +x ./*.AppImage && ./*.AppImage
# or
sudo apt install ./*.deb

Updates are disabled in these test builds. Artifacts expire in 14 days.
Built from this PR's code: read the changes before running it.

Full workflow run

@SuperKali

Copy link
Copy Markdown
Member Author

@shvmm could you kindly test one more thing with your card reader? This PR should make a write-protected SD card show as Locked on Windows. Using the Windows build from the test builds comment above, insert the card with the lock switch off (it should be selectable), then slide the switch on and reinsert it (it should now show as Locked); there is no need to flash anything. If it doesn't show as Locked, please upload the log from the app and paste the link here.

@github-actions github-actions Bot added the status: ready for review Ready to be reviewed label Nov 13, 2026
@shvmm

shvmm commented Nov 13, 2026 •

Copy link
Copy Markdown

@shvmm could you kindly test one more thing with your card reader? This PR should make a write-protected SD card show as Locked on Windows. Using the Windows build from the test builds comment above, insert the card with the lock switch off (it should be selectable), then slide the switch on and reinsert it (it should now show as Locked); there is no need to flash anything. If it doesn't show as Locked, please upload the log from the app and paste the link here.

it says read_only=false even when I slide the lock card tab and reinsert.
Curiously, windows allows me to write to the SD Card even with the lock switch ON.
I'm using a microSD with a SD adapter BTW.
Does that switch even do anything or do I need to confirm with another adapter ?

EDIT: Tested the same SD adapter on Linux and it correctly shows (ro) flag in dmesg.

https://paste.armbian.com/ujikawuragumokil

Also can the main flashing and verifying interfaces could expose more details during the operations. Like speed in MB/s, current filename, files count. (maybe hide them under a collapsible arrow)

@SuperKali

Copy link
Copy Markdown
Member Author

@shvmm thanks, that answers it. Your log shows Windows reporting the card as writable with the switch on (media_characteristics=0x80000008, write-protect bit clear), and Windows lets you write to it, so the reader's Windows driver ignores the switch and the app has nothing to read. If you have a USB card reader around, the same test on it would show me whether Locked appears when the driver does report the switch. Speed and more details during flashing is a fair request, could you open a separate issue for it?

@shvmm

shvmm commented Nov 13, 2026

Copy link
Copy Markdown

Don't have an external USB Card reader.
I've Two laptops with internal SD card readers. One running linux respects lock switch, the one running Win11 doesn't.

But I've a camera that exposes itself as removable disk. I should maybe check write protect there

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready for review Ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants